#include "MathExpress.h"
#include "calculator.h"
#include "MathErr.h"
#include <fstream>

using namespace std;

int main()
{
    string expression;
    ofstream out("output.txt");
    calculator new_calculator;
    while (getline(cin, expression))
    {
        MathExpress tmp(expression);
        cout << tmp << " = ";
        out << tmp << " = ";
        try
        {
            cout << new_calculator.calculate(tmp) << endl;
            out << new_calculator.calculate(tmp) << endl;
        }
        catch (MathErr &e)
        {

            e.what(out);
            cerr << '\n';
            out << '\n';
        }
    }
}